package com.hjs.community.search.init;

import com.hjs.community.search.service.SearchPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class ESInit implements ApplicationRunner {

    @Autowired
    private SearchPostService searchPostService;

    @Value("${community.post.indexName}")
    private String index;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (!searchPostService.hasExists(index)) {
            searchPostService.createPostIndex();
        }
    }
}
